home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 6084 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.1 KB  |  42 lines

  1. Path: taco.cc.ncsu.edu!boyle
  2. From: boyle@laue.chem.ncsu.edu (Paul D. Boyle)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: How do I use abs() on floats ?
  5. Date: 22 Feb 1996 14:17:51 GMT
  6. Organization: North Carolina State University
  7. Message-ID: <4ghtuf$u5h@taco.cc.ncsu.edu>
  8. References: <4ghki0$b44@LNCSEX0003.eu.btco.com>
  9. NNTP-Posting-Host: laue.chem.ncsu.edu
  10. X-Newsreader: TIN [version 1.2 PL2]
  11.  
  12. DaveMx wrote:
  13. : What's the easiest way to get the absolute scalar value of a float.
  14. : I need to test to see of a variable is 'bigger' than a certain tolerance.
  15.  
  16. : e.g.
  17.  
  18. : if ( abs (error__float)  > MAX_TOLERANCE )   printf ( "Tolerance level
  19.  exceeded \n" );
  20.  
  21.  
  22. : BUT the abs() function says it only works on int 's . Any ideas how to do
  23. : it for floats in the most elegant way ???
  24.  
  25. Try the fabs() function
  26. #include <math.h>
  27.  
  28. Prototype:  double fabs( double x );
  29.  
  30. Later,
  31.  
  32. Paul
  33.  
  34. __
  35. Paul D. Boyle                |    boyle@laue.chem.ncsu.edu
  36. Director, X-ray Structural Facility |    phone: (919) 515-7362
  37. Department of Chemistry - Box 8204  |    FAX:   (919) 515-5079
  38. North Carolina State University     | 
  39. Raleigh, NC, 27695-8204
  40. http://laue.chem.ncsu.edu/web/xray.welcome.html
  41.  
  42.